<?php


namespace app\api\controller;


use app\api\model\CaseModel;
use app\api\model\CaseRecordModel;
use app\api\model\FollowRecordModel;
use app\api\model\GoodsModel;
use app\api\validate\CaseValidate;
use app\api\validate\FollowRecordValidate;
use think\Db;
use think\Exception;

class Case1 extends ApiBase
{


    /**
     *
     * 案例档案列表
     */
    public function caseList(){

        $params = input();
        $params['user_id'] = $this->id;
        $data = CaseModel::caseList($params);
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 病例添加或编辑
     */
    public function caseAdd(CaseValidate $request){

        $params = $this->request->post();
        $params['user_id'] = $this->id;
        if (!$request->scene('caseAdd')->check($params)){

            $this->fail($request->getError());
        }

        $res = CaseModel::caseAdd($params);
        if ($res){

            $this->successful('操作成功');
        }else{

            $this->fail('操作失败');
        }

    }

    /**
     *
     * 病例详情
     */
    public function caseInfo(){

        $params = $this->request->get();
        if (!isset($params['id']) || empty($params['id'])){

            $this->fail('缺少病例id');
        }
        $data = CaseModel::caseInfo($params['id']);
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 添加或编辑随访记录
     */
    public function followRecordAdd(FollowRecordValidate $request){

        $params = $this->request->post();
        $params['user_id'] = $this->id;
        if (!$request->scene('followRecordAdd')->check($params)){

            $this->fail($request->getError());
        }

        $res = FollowRecordModel::followRecordAdd($params);
        if ($res){

            $this->successful('操作成功');
        }else{

            $this->fail('操作失败');
        }
    }

    /**
     *
     * 随访记录详情
     */
    public function followRecordInfo(){

        $params = $this->request->get();
        if (!isset($params['id']) || empty($params['id'])){

            $this->fail('缺少随访记录id');
        }
        $data = FollowRecordModel::followRecordInfo($params['id']);
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 删除随访记录
     */
    public function followRecordDel(){

        $params = $this->request->get();
        if (!isset($params['id']) || empty($params['id'])){

            $this->fail('缺少随访记录id');
        }
        $res = FollowRecordModel::followRecordDel($params['id']);
        if ($res){

            $this->successful('操作成功');
        }else{

            $this->fail('操作失败');
        }
    }

}